home *** CD-ROM | disk | FTP | other *** search
/ Personal Computer World 2005 October / PCWOCT05.iso / Software / FromTheMag / The GIMP 2.2.8 / gimp-2.2.8-i586-setup.exe / {app} / share / gimp / 2.0 / scripts / neon-logo.scm < prev    next >
Encoding:
GIMP Script-Fu Script  |  2005-06-30  |  6.7 KB  |  227 lines

  1. ;  NEON
  2. ;  Create a text effect that simulates neon lighting
  3.  
  4. (define (set-pt a index x y)
  5.   (prog1
  6.    (aset a (* index 2) x)
  7.    (aset a (+ (* index 2) 1) y)))
  8.  
  9. (define (neon-spline1)
  10.   (let* ((a (cons-array 6 'byte)))
  11.     (set-pt a 0 0 0)
  12.     (set-pt a 1 127 145)
  13.     (set-pt a 2 255 255)
  14.     a))
  15.  
  16. (define (neon-spline2)
  17.   (let* ((a (cons-array 6 'byte)))
  18.     (set-pt a 0 0 0)
  19.     (set-pt a 1 110 150)
  20.     (set-pt a 2 255 255)
  21.     a))
  22.  
  23. (define (neon-spline3)
  24.   (let* ((a (cons-array 6 'byte)))
  25.     (set-pt a 0 0 0)
  26.     (set-pt a 1 100 185)
  27.     (set-pt a 2 255 255)
  28.     a))
  29.  
  30. (define (neon-spline4)
  31.   (let* ((a (cons-array 8 'byte)))
  32.     (set-pt a 0 0 0)
  33.     (set-pt a 1 64 64)
  34.     (set-pt a 2 127 192)
  35.     (set-pt a 3 255 255)
  36.     a))
  37.  
  38. (define (find-hue-offset color)
  39.   (let* ((R (car color))
  40.      (G (cadr color))
  41.      (B (caddr color))
  42.      (max-val (max R G B))
  43.      (min-val (min R G B))
  44.      (delta (- max-val min-val))
  45.      (hue 0))
  46.     (if (= delta 0) 0
  47.     (begin
  48.       (cond ((= max-val R) (set! hue (/ (- G B) (* 1.0 delta))))
  49.         ((= max-val G) (set! hue (+ 2 (/ (- B R) (* 1.0 delta)))))
  50.         ((= max-val B) (set! hue (+ 4 (/ (- R G) (* 1.0 delta))))))
  51.       (set! hue (* hue 60))
  52.       (if (< hue 0) (set! hue (+ hue 360)))
  53.       (if (> hue 360) (set! hue (- hue 360)))
  54.       (if (> hue 180) (set! hue (- hue 360)))
  55.       hue))))
  56.  
  57. (define (apply-neon-logo-effect img
  58.                 tube-layer
  59.                 size
  60.                 bg-color
  61.                 glow-color
  62.                 shadow)
  63.   (let* ((tube-hue (find-hue-offset glow-color))
  64.      (shrink (/ size 14))
  65.      (grow (/ size 40))
  66.      (feather (/ size 5))
  67.      (feather1 (/ size 25))
  68.      (feather2 (/ size 12))
  69.      (inc-shrink (/ size 100))
  70.      (shadow-shrink (/ size 40))
  71.      (shadow-feather (/ size 20))
  72.      (shadow-offx (/ size 10))
  73.      (shadow-offy (/ size 10))
  74.      (width (car (gimp-drawable-width tube-layer)))
  75.      (height (car (gimp-drawable-height tube-layer)))
  76.      (glow-layer (car (gimp-layer-new img width height RGBA-IMAGE "Neon Glow" 100 NORMAL-MODE)))
  77.      (bg-layer (car (gimp-layer-new img width height RGB-IMAGE "Background" 100 NORMAL-MODE)))
  78.      (shadow-layer (if (= shadow TRUE)
  79.                (car (gimp-layer-new img width height RGBA-IMAGE "Shadow" 100 NORMAL-MODE))
  80.                0))
  81.      (selection 0))
  82.  
  83.     (gimp-context-push)
  84.  
  85.     (script-fu-util-image-resize-from-layer img tube-layer)
  86.     (gimp-image-add-layer img bg-layer 1)
  87.     (if (not (= shadow 0))
  88.     (begin
  89.       (gimp-image-add-layer img shadow-layer 1)
  90.       (gimp-edit-clear shadow-layer)))
  91.     (gimp-image-add-layer img glow-layer 1)
  92.  
  93.     (gimp-context-set-background '(0 0 0))
  94.     (gimp-selection-layer-alpha tube-layer)
  95.     (set! selection (car (gimp-selection-save img)))
  96.     (gimp-selection-none img)
  97.  
  98.     (gimp-edit-clear glow-layer)
  99.     (gimp-edit-clear tube-layer)
  100.  
  101.     (gimp-context-set-background bg-color)
  102.     (gimp-edit-fill bg-layer BACKGROUND-FILL)
  103.  
  104.     (gimp-selection-load selection)
  105.     (gimp-context-set-background '(255 255 255))
  106.     (gimp-edit-fill tube-layer BACKGROUND-FILL)
  107.     (gimp-selection-shrink img shrink)
  108.     (gimp-context-set-background '(0 0 0))
  109.     (gimp-edit-fill selection BACKGROUND-FILL)
  110.     (gimp-edit-clear tube-layer)
  111.  
  112.     (gimp-selection-none img)
  113.     (if (not (= feather1 0)) (plug-in-gauss-rle 1 img tube-layer feather1 TRUE TRUE))
  114.     (gimp-selection-load selection)
  115.     (if (not (= feather2 0)) (plug-in-gauss-rle 1 img tube-layer feather2 TRUE TRUE))
  116.  
  117.     (gimp-selection-feather img inc-shrink)
  118.     (gimp-selection-shrink img inc-shrink)
  119.     (gimp-curves-spline tube-layer 4 6 (neon-spline1))
  120.  
  121.     (gimp-selection-load selection)
  122.     (gimp-selection-feather img inc-shrink)
  123.     (gimp-selection-shrink img (* inc-shrink 2))
  124.     (gimp-curves-spline tube-layer 4 6 (neon-spline2))
  125.  
  126.     (gimp-selection-load selection)
  127.     (gimp-selection-feather img inc-shrink)
  128.     (gimp-selection-shrink img (* inc-shrink 3))
  129.     (gimp-curves-spline tube-layer 4 6 (neon-spline3))
  130.  
  131.     (gimp-layer-set-preserve-trans tube-layer 1)
  132.     (gimp-selection-layer-alpha tube-layer)
  133.     (gimp-selection-invert img)
  134.     (gimp-context-set-background glow-color)
  135.     (gimp-edit-fill tube-layer BACKGROUND-FILL)
  136.  
  137.     (gimp-selection-none img)
  138.     (gimp-layer-set-preserve-trans tube-layer 0)
  139.     (gimp-curves-spline tube-layer 4 8 (neon-spline4))
  140.  
  141.     (gimp-selection-load selection)
  142.     (gimp-selection-grow img grow)
  143.     (gimp-selection-invert img)
  144.     (gimp-edit-clear tube-layer)
  145.     (gimp-selection-invert img)
  146.  
  147.     (gimp-selection-feather img feather)
  148.     (gimp-edit-fill glow-layer BACKGROUND-FILL)
  149.  
  150.     (if (not (= shadow 0))
  151.     (begin
  152.           (gimp-selection-load selection)
  153.           (gimp-selection-grow img grow)
  154.       (gimp-selection-shrink img shadow-shrink)
  155.       (gimp-selection-feather img shadow-feather)
  156.       (gimp-selection-translate img shadow-offx shadow-offy)
  157.       (gimp-context-set-background '(0 0 0))
  158.       (gimp-edit-fill shadow-layer BACKGROUND-FILL)))
  159.     (gimp-selection-none img)
  160.  
  161.     (gimp-drawable-set-name tube-layer "Neon Tubes")
  162.     (gimp-image-remove-channel img selection)
  163.  
  164.     (gimp-context-pop)))
  165.  
  166. (define (script-fu-neon-logo-alpha img
  167.                    tube-layer
  168.                    size
  169.                    bg-color
  170.                    glow-color
  171.                    shadow)
  172.   (begin
  173.     (gimp-image-undo-group-start img)
  174.     (apply-neon-logo-effect img tube-layer size bg-color glow-color shadow)
  175.     (gimp-image-undo-group-end img)
  176.     (gimp-displays-flush)))
  177.  
  178. (script-fu-register "script-fu-neon-logo-alpha"
  179.             _"N_eon..."
  180.             "Neon logos"
  181.             "Spencer Kimball"
  182.             "Spencer Kimball"
  183.             "1997"
  184.             "RGBA"
  185.                     SF-IMAGE      "Image"             0
  186.                     SF-DRAWABLE   "Drawable"          0
  187.             SF-ADJUSTMENT _"Effect size (pixels * 5)" '(150 2 1000 1 10 0 1)
  188.             SF-COLOR      _"Background color" '(0 0 0)
  189.             SF-COLOR      _"Glow color"       '(38 211 255)
  190.             SF-TOGGLE     _"Create shadow"    FALSE)
  191.  
  192. (script-fu-menu-register "script-fu-neon-logo-alpha"
  193.              _"<Image>/Script-Fu/Alpha to Logo")
  194.  
  195.  
  196. (define (script-fu-neon-logo text
  197.                  size
  198.                  font
  199.                  bg-color
  200.                  glow-color
  201.                  shadow)
  202.   (let* ((img (car (gimp-image-new 256 256 RGB)))
  203.      (border (/ size 4))
  204.      (tube-layer (car (gimp-text-fontname img -1 0 0 text border TRUE size PIXELS font))))
  205.     (gimp-image-undo-disable img)
  206.     (gimp-drawable-set-name tube-layer text)
  207.     (apply-neon-logo-effect img tube-layer size bg-color glow-color shadow)
  208.     (gimp-image-undo-enable img)
  209.     (gimp-display-new img)))
  210.  
  211. (script-fu-register "script-fu-neon-logo"
  212.             _"N_eon..."
  213.             "Neon logos"
  214.             "Spencer Kimball"
  215.             "Spencer Kimball"
  216.             "1997"
  217.             ""
  218.             SF-STRING     _"Text"               "NEON"
  219.             SF-ADJUSTMENT _"Font size (pixels)" '(150 2 1000 1 10 0 1)
  220.             SF-FONT       _"Font"               "Blippo"
  221.             SF-COLOR      _"Background color"   '(0 0 0)
  222.             SF-COLOR      _"Glow color"         '(38 211 255)
  223.             SF-TOGGLE     _"Create shadow"      FALSE)
  224.  
  225. (script-fu-menu-register "script-fu-neon-logo"
  226.              _"<Toolbox>/Xtns/Script-Fu/Logos")
  227.